
package com.jf.cloud.product.controller.multishop;

import com.jf.cloud.common.database.dto.PageDTO;
import com.jf.cloud.common.database.vo.PageVO;
import com.jf.cloud.common.response.ServerResponseEntity;
import com.jf.cloud.product.dto.StockChangeReasonStatusDTO;
import com.jf.cloud.product.model.StockChangeReasonStatus;
import com.jf.cloud.product.service.StockChangeReasonStatusService;
import io.swagger.v3.oas.annotations.tags.Tag;
import io.swagger.v3.oas.annotations.Operation;
import ma.glasnost.orika.MapperFacade;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.validation.Valid;

/**
 * 出入库原因状态
 *
 * @author zz
 * @date 2022-06-22 17:14:22
 */
@RestController("multishopStockChangeReasonStatusController")
@RequestMapping("/m/stock_change_reason_status")
@Tag(name = "出入库原因状态")
public class StockChangeReasonStatusController {

    @Autowired
    private StockChangeReasonStatusService stockChangeReasonStatusService;

    @Autowired
    private MapperFacade mapperFacade;

    @GetMapping("/page")
    @Operation(summary = "获取出入库原因状态列表" , description = "分页获取出入库原因状态列表")
    public ServerResponseEntity<PageVO<StockChangeReasonStatus>> page(@Valid PageDTO pageDTO) {
        PageVO<StockChangeReasonStatus> stockChangeReasonStatusPage = stockChangeReasonStatusService.page(pageDTO);
        return ServerResponseEntity.success(stockChangeReasonStatusPage);
    }

    @GetMapping
    @Operation(summary = "获取出入库原因状态" , description = "根据stockChangeReasonStatusId获取出入库原因状态")
    public ServerResponseEntity<StockChangeReasonStatus> getByStockChangeReasonStatusId(@RequestParam Long stockChangeReasonStatusId) {
        return ServerResponseEntity.success(stockChangeReasonStatusService.getByStockChangeReasonStatusId(stockChangeReasonStatusId));
    }

    @PostMapping
    @Operation(summary = "保存出入库原因状态" , description = "保存出入库原因状态")
    public ServerResponseEntity<Void> save(@Valid @RequestBody StockChangeReasonStatusDTO stockChangeReasonStatusDTO) {
        StockChangeReasonStatus stockChangeReasonStatus = mapperFacade.map(stockChangeReasonStatusDTO, StockChangeReasonStatus.class);
        stockChangeReasonStatus.setStockChangeReasonStatusId(null);
        stockChangeReasonStatusService.save(stockChangeReasonStatus);
        return ServerResponseEntity.success();
    }

    @PutMapping
    @Operation(summary = "更新出入库原因状态" , description = "更新出入库原因状态")
    public ServerResponseEntity<Void> update(@Valid @RequestBody StockChangeReasonStatusDTO stockChangeReasonStatusDTO) {
        StockChangeReasonStatus stockChangeReasonStatus = mapperFacade.map(stockChangeReasonStatusDTO, StockChangeReasonStatus.class);
        stockChangeReasonStatusService.update(stockChangeReasonStatus);
        return ServerResponseEntity.success();
    }

    @DeleteMapping
    @Operation(summary = "删除出入库原因状态" , description = "根据出入库原因状态id删除出入库原因状态")
    public ServerResponseEntity<Void> delete(@RequestParam Long stockChangeReasonStatusId) {
        stockChangeReasonStatusService.deleteById(stockChangeReasonStatusId);
        return ServerResponseEntity.success();
    }
}
